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

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

b = A("b")
g = B("g")
d = B("d")
c = B("c")
n = B("n")
f = B("f")
i = A("i")
h = A("h")
e = A("e")

b.p = d
g.y = h
d.y = e
c.y = b
n.y = i
f.y = e
i.p = c
h.p = c
e.p = c
assert c.y.p.y.p.y.p.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

b = A("b")
g = B("g")
d = B("d")
c = B("c")
n = B("n")
f = B("f")
i = A("i")
h = A("h")
e = A("e")

b.p = d
g.y = h
d.y = e
c.y = b
n.y = i
f.y = e
i.p = c
h.p = c
e.p = c
assert c.y.p.y.p.y.p.y.p.txt == "c"