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

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

b = A("b")
f = B("f")
d = B("d")
g = A("g")
j = A("j")
e = B("e")

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

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

b = A("b")
f = B("f")
d = B("d")
g = A("g")
j = A("j")
e = B("e")

b.s = d
f.u = d
f.s = b
d.u = e
d.s = b
g.s = e
j.s = d
e.u = f
e.s = j
assert j.s.u.u.txt == "f"