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

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

a = A("a")
f = B("f")
b = A("b")
d = B("d")
j = A("j")
k = B("k")

a.x = f
f.u = d
b.x = d
d.u = f
j.x = k
k.u = d
assert k.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
b = A("b")
d = B("d")
j = A("j")
k = B("k")

a.x = f
f.u = d
b.x = d
d.u = f
j.x = k
k.u = d
assert k.u.u.u.txt == "d"