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

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

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

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

f = A("f")
b = B("b")
n = C("n")
d = D("d")

f.x = b
b.p = d
b.q = f
b.s = n
b.t = n
n.w = d
n.v = d
n.r = b
d.p = n
d.w = n
assert n.r.q.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
n = C("n")
d = D("d")

f.x = b
b.p = d
b.q = f
b.s = n
b.t = n
n.w = d
n.v = d
n.r = b
d.p = n
d.w = n
assert n.r.q.x.q.txt == "f"