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

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

d = A("d")
g = B("g")
c = A("c")
m = A("m")
k = B("k")
l = A("l")
b = B("b")

d.x = l
g.p = b
g.z = m
c.x = m
m.x = l
k.p = b
k.z = d
l.x = m
b.p = k
b.z = d
assert l.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

d = A("d")
g = B("g")
c = A("c")
m = A("m")
k = B("k")
l = A("l")
b = B("b")

d.x = l
g.p = b
g.z = m
c.x = m
m.x = l
k.p = b
k.z = d
l.x = m
b.p = k
b.z = d
assert l.x.x.x.x.x.txt == "m"