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

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

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

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

f = A("f")
d = B("d")
j = C("j")
k = D("k")

f.v = k
d.x = k
d.p = k
d.t = j
d.v = f
j.p = f
k.o = j
k.w = j
k.x = f
k.t = f
assert f.v.t.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

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

f = A("f")
d = B("d")
j = C("j")
k = D("k")

f.v = k
d.x = k
d.p = k
d.t = j
d.v = f
j.p = f
k.o = j
k.w = j
k.x = f
k.t = f
assert f.v.t.v.t.txt == "f"