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

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

l = A("l")
f = B("f")
c = A("c")
n = B("n")
d = B("d")
g = B("g")
m = B("m")
e = A("e")

l.z = c
l.y = c
f.x = n
c.z = e
c.y = l
n.x = m
d.x = f
g.x = d
m.x = n
e.z = l
e.y = l
assert m.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: A = None
        self.txt = txt

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

l = A("l")
f = B("f")
c = A("c")
n = B("n")
d = B("d")
g = B("g")
m = B("m")
e = A("e")

l.z = c
l.y = c
f.x = n
c.z = e
c.y = l
n.x = m
d.x = f
g.x = d
m.x = n
e.z = l
e.y = l
assert m.x.x.x.txt == "n"