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

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

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

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

m = A("m")
d = B("d")
n = C("n")
a = D("a")

m.r = n
m.q = d
d.r = m
n.u = d
n.o = m
a.t = d
a.u = d
a.x = n
assert d.r.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: B = None
        self.txt = txt

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

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

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

m = A("m")
d = B("d")
n = C("n")
a = D("a")

m.r = n
m.q = d
d.r = m
n.u = d
n.o = m
a.t = d
a.u = d
a.x = n
assert d.r.r.u.txt == "d"