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

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

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

f = A("f")
n = B("n")
m = C("m")
d = B("d")
b = C("b")
a = A("a")

f.o = m
f.z = m
f.w = b
n.v = d
n.o = f
m.x = a
m.p = f
d.v = n
d.o = a
b.x = f
b.p = a
a.o = b
a.w = m
a.z = m
assert f.o.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.w: C = None
        self.z: C = None
        self.txt = txt

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

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

f = A("f")
n = B("n")
m = C("m")
d = B("d")
b = C("b")
a = A("a")

f.o = m
f.z = m
f.w = b
n.v = d
n.o = f
m.x = a
m.p = f
d.v = n
d.o = a
b.x = f
b.p = a
a.o = b
a.w = m
a.z = m
assert f.o.x.o.x.txt == "f"