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

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

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

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

j = A("j")
b = B("b")
c = C("c")
g = D("g")

j.r = c
j.q = c
j.x = c
b.z = c
b.q = g
b.x = j
c.w = g
c.s = g
c.r = g
c.q = b
g.u = b
g.p = b
assert g.p.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: C = None
        self.x: C = None
        self.txt = txt

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

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

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

j = A("j")
b = B("b")
c = C("c")
g = D("g")

j.r = c
j.q = c
j.x = c
b.z = c
b.q = g
b.x = j
c.w = g
c.s = g
c.r = g
c.q = b
g.u = b
g.p = b
assert g.p.z.q.z.txt == "c"