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

i = A("i")
g = B("g")
h = B("h")
n = A("n")
c = B("c")
j = B("j")
f = A("f")
b = B("b")
d = B("d")

i.x = g
g.u = b
h.u = c
n.x = d
c.u = b
j.u = d
f.x = j
b.u = g
d.u = j
assert d.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

i = A("i")
g = B("g")
h = B("h")
n = A("n")
c = B("c")
j = B("j")
f = A("f")
b = B("b")
d = B("d")

i.x = g
g.u = b
h.u = c
n.x = d
c.u = b
j.u = d
f.x = j
b.u = g
d.u = j
assert d.u.u.u.txt == "j"