class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

g = A("g")
d = B("d")
k = A("k")

g.u = d
g.s = k
d.s = g
k.u = d
k.s = g
assert g.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

g = A("g")
d = B("d")
k = A("k")

g.u = d
g.s = k
d.s = g
k.u = d
k.s = g
assert g.s.u.s.txt == "g"