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

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

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

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

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

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

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