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

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

d = A("d")
i = B("i")
n = B("n")
a = A("a")
f = B("f")
l = A("l")
g = A("g")
k = B("k")
b = B("b")

d.p = a
d.y = l
i.u = f
n.u = i
a.p = l
a.y = g
f.u = i
l.p = d
l.y = a
g.p = l
g.y = a
k.u = i
b.u = n
assert n.u.u.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.y: A = None
        self.txt = txt

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

d = A("d")
i = B("i")
n = B("n")
a = A("a")
f = B("f")
l = A("l")
g = A("g")
k = B("k")
b = B("b")

d.p = a
d.y = l
i.u = f
n.u = i
a.p = l
a.y = g
f.u = i
l.p = d
l.y = a
g.p = l
g.y = a
k.u = i
b.u = n
assert n.u.u.u.u.u.u.u.txt == "i"