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

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

j = A("j")
e = B("e")
h = A("h")
a = B("a")
f = B("f")
b = B("b")
k = A("k")
g = A("g")
l = A("l")

j.r = g
e.z = k
e.y = j
h.r = k
a.z = g
a.y = j
f.z = h
f.y = h
b.z = g
b.y = l
k.r = h
g.r = h
l.r = h
assert e.z.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

j = A("j")
e = B("e")
h = A("h")
a = B("a")
f = B("f")
b = B("b")
k = A("k")
g = A("g")
l = A("l")

j.r = g
e.z = k
e.y = j
h.r = k
a.z = g
a.y = j
f.z = h
f.y = h
b.z = g
b.y = l
k.r = h
g.r = h
l.r = h
assert e.z.r.r.r.r.r.r.r.txt == "h"