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

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

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

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

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

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

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

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

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

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

k.t = n
f.x = n
f.p = j
j.q = f
j.t = k
j.x = k
j.r = n
n.t = k
n.r = f
n.v = f
n.p = j
assert k.t.p.t.txt == "k"