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

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

l = A("l")
b = B("b")
d = B("d")
f = B("f")
a = A("a")
j = A("j")
i = B("i")

l.p = a
l.z = b
b.p = j
d.p = j
f.p = j
a.p = l
a.z = i
j.p = l
j.z = d
i.p = a
assert b.p.p.z.p.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.z: B = None
        self.txt = txt

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

l = A("l")
b = B("b")
d = B("d")
f = B("f")
a = A("a")
j = A("j")
i = B("i")

l.p = a
l.z = b
b.p = j
d.p = j
f.p = j
a.p = l
a.z = i
j.p = l
j.z = d
i.p = a
assert b.p.p.z.p.z.p.txt == "j"