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

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

d = A("d")
m = B("m")
k = A("k")
g = A("g")
h = A("h")
a = A("a")
i = A("i")
c = A("c")
f = B("f")

d.p = g
m.t = h
k.p = d
g.p = h
h.p = d
a.p = k
i.p = d
c.p = h
f.t = k
assert f.t.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.t: A = None
        self.txt = txt

d = A("d")
m = B("m")
k = A("k")
g = A("g")
h = A("h")
a = A("a")
i = A("i")
c = A("c")
f = B("f")

d.p = g
m.t = h
k.p = d
g.p = h
h.p = d
a.p = k
i.p = d
c.p = h
f.t = k
assert f.t.p.p.p.p.p.txt == "g"