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

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

l = A("l")
j = B("j")
i = A("i")
d = A("d")
e = A("e")
k = A("k")
m = A("m")
h = B("h")
f = B("f")

l.p = f
l.y = h
j.r = f
i.p = h
i.y = j
d.p = f
d.y = h
e.p = j
e.y = h
k.p = j
k.y = f
m.p = h
m.y = f
h.r = j
f.r = h
assert f.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: B = None
        self.txt = txt

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

l = A("l")
j = B("j")
i = A("i")
d = A("d")
e = A("e")
k = A("k")
m = A("m")
h = B("h")
f = B("f")

l.p = f
l.y = h
j.r = f
i.p = h
i.y = j
d.p = f
d.y = h
e.p = j
e.y = h
k.p = j
k.y = f
m.p = h
m.y = f
h.r = j
f.r = h
assert f.r.r.r.r.r.r.txt == "f"