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

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

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

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

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

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

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