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

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

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

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

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

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

j.x = i
j.z = k
i.x = e
d.x = e
d.z = k
k.x = i
e.x = i
g.x = k
g.z = e
m.x = i
m.z = e
assert i.x.x.x.x.x.x.txt == "i"