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

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

h = A("h")
c = B("c")
j = B("j")
f = B("f")
e = A("e")
b = A("b")
n = A("n")
g = B("g")

h.r = g
c.z = j
j.z = g
f.z = g
e.r = j
b.r = g
n.r = f
g.z = f
assert j.z.z.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

h = A("h")
c = B("c")
j = B("j")
f = B("f")
e = A("e")
b = A("b")
n = A("n")
g = B("g")

h.r = g
c.z = j
j.z = g
f.z = g
e.r = j
b.r = g
n.r = f
g.z = f
assert j.z.z.z.z.z.z.z.z.txt == "f"