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

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

l = A("l")
a = B("a")
g = A("g")
k = A("k")
d = A("d")
f = A("f")
h = B("h")
b = B("b")

l.p = k
a.z = k
a.t = f
g.p = d
k.p = d
d.p = g
f.p = l
h.z = f
h.t = k
b.z = f
b.t = f
assert g.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

l = A("l")
a = B("a")
g = A("g")
k = A("k")
d = A("d")
f = A("f")
h = B("h")
b = B("b")

l.p = k
a.z = k
a.t = f
g.p = d
k.p = d
d.p = g
f.p = l
h.z = f
h.t = k
b.z = f
b.t = f
assert g.p.p.p.p.p.txt == "d"