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

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

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

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

f = A("f")
b = B("b")
m = C("m")
j = D("j")
a = C("a")
e = B("e")

f.v = m
f.p = a
b.p = f
m.p = a
j.q = f
j.p = f
j.o = f
j.z = e
a.p = m
e.p = f
assert e.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
m = C("m")
j = D("j")
a = C("a")
e = B("e")

f.v = m
f.p = a
b.p = f
m.p = a
j.q = f
j.p = f
j.o = f
j.z = e
a.p = m
e.p = f
assert e.p.p.p.p.txt == "a"