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

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

i = A("i")
f = B("f")
m = A("m")
d = A("d")
c = A("c")
k = A("k")
g = B("g")
e = B("e")

i.u = f
i.z = e
f.x = g
m.u = f
m.z = f
d.u = e
d.z = f
c.u = f
c.z = g
k.u = e
k.z = f
g.x = e
e.x = f
assert f.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.z: B = None
        self.txt = txt

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

i = A("i")
f = B("f")
m = A("m")
d = A("d")
c = A("c")
k = A("k")
g = B("g")
e = B("e")

i.u = f
i.z = e
f.x = g
m.u = f
m.z = f
d.u = e
d.z = f
c.u = f
c.z = g
k.u = e
k.z = f
g.x = e
e.x = f
assert f.x.x.x.x.x.x.txt == "f"