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

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.o: D = None
        self.q: D = None
        self.txt = txt

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

f.x = a
b.p = a
b.v = f
a.v = j
n.r = f
n.t = f
n.o = j
n.q = j
j.r = f
j.t = f
j.o = n
j.q = n
assert b.v.x.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.o: D = None
        self.q: D = None
        self.txt = txt

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

f.x = a
b.p = a
b.v = f
a.v = j
n.r = f
n.t = f
n.o = j
n.q = j
j.r = f
j.t = f
j.o = n
j.q = n
assert b.v.x.v.r.txt == "f"