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

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

c = A("c")
d = B("d")
e = A("e")
m = A("m")
g = B("g")
a = A("a")
h = A("h")
b = A("b")

c.p = b
d.x = g
e.p = b
m.p = b
g.x = d
a.p = m
h.p = m
b.p = m
assert b.p.p.p.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.x: B = None
        self.txt = txt

c = A("c")
d = B("d")
e = A("e")
m = A("m")
g = B("g")
a = A("a")
h = A("h")
b = A("b")

c.p = b
d.x = g
e.p = b
m.p = b
g.x = d
a.p = m
h.p = m
b.p = m
assert b.p.p.p.p.p.p.p.p.txt == "b"