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

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

l = A("l")
f = B("f")
m = B("m")
a = B("a")
h = A("h")

l.x = h
l.v = h
f.z = h
f.r = a
m.z = l
m.r = f
a.z = l
a.r = m
h.x = l
h.v = l
assert f.r.r.z.x.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.v: A = None
        self.txt = txt

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

l = A("l")
f = B("f")
m = B("m")
a = B("a")
h = A("h")

l.x = h
l.v = h
f.z = h
f.r = a
m.z = l
m.r = f
a.z = l
a.r = m
h.x = l
h.v = l
assert f.r.r.z.x.v.txt == "l"