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

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

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

f = A("f")
l = B("l")
c = C("c")
e = B("e")
a = A("a")
d = C("d")
k = A("k")

f.o = k
l.v = c
l.r = a
c.z = e
c.p = l
c.q = l
e.v = d
e.r = a
a.o = f
d.z = l
d.q = l
d.p = e
k.o = f
assert d.z.r.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

f = A("f")
l = B("l")
c = C("c")
e = B("e")
a = A("a")
d = C("d")
k = A("k")

f.o = k
l.v = c
l.r = a
c.z = e
c.p = l
c.q = l
e.v = d
e.r = a
a.o = f
d.z = l
d.q = l
d.p = e
k.o = f
assert d.z.r.o.txt == "f"