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

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

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

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

f = A("f")
j = B("j")
i = C("i")
e = D("e")
b = C("b")
k = D("k")

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

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

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

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

f = A("f")
j = B("j")
i = C("i")
e = D("e")
b = C("b")
k = D("k")

f.x = i
j.q = f
j.v = e
i.v = j
e.o = f
e.z = k
b.v = j
k.o = f
k.z = e
assert f.x.v.q.txt == "f"