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

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

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

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

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

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

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