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

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

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

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

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

g.x = b
g.u = d
b.q = n
b.u = n
b.s = n
b.v = g
n.r = d
d.x = n
d.z = n
d.t = g
assert d.t.x.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: D = None
        self.txt = txt

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

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

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

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

g.x = b
g.u = d
b.q = n
b.u = n
b.s = n
b.v = g
n.r = d
d.x = n
d.z = n
d.t = g
assert d.t.x.u.r.txt == "d"