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

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

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

f = A("f")
l = B("l")
d = C("d")
n = A("n")
g = C("g")
h = B("h")

f.r = l
f.z = h
l.v = d
d.v = h
n.r = l
n.z = h
g.v = h
h.v = d
assert f.r.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: B = None
        self.txt = txt

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

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

f = A("f")
l = B("l")
d = C("d")
n = A("n")
g = C("g")
h = B("h")

f.r = l
f.z = h
l.v = d
d.v = h
n.r = l
n.z = h
g.v = h
h.v = d
assert f.r.v.v.txt == "h"