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

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

m = A("m")
k = B("k")
j = B("j")
l = B("l")
d = A("d")
e = A("e")
n = B("n")
c = B("c")
h = B("h")

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

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

m = A("m")
k = B("k")
j = B("j")
l = B("l")
d = A("d")
e = A("e")
n = B("n")
c = B("c")
h = B("h")

m.x = e
m.p = k
k.r = j
j.r = h
l.r = n
d.x = e
d.p = n
e.x = d
e.p = n
n.r = c
c.r = j
h.r = j
assert h.r.r.r.r.r.r.r.r.txt == "h"