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

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

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

g.p = h
b.y = g
m.y = g
l.y = h
e.y = g
n.y = g
h.p = g
c.y = g
f.y = h
d.y = h
assert c.y.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.y: A = None
        self.txt = txt

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

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