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

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

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

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

c = A("c")
b = B("b")
m = C("m")
a = D("a")
i = A("i")

c.r = m
c.q = b
c.x = b
b.s = m
b.t = m
b.y = i
b.x = a
m.o = a
a.t = b
i.r = m
i.q = b
i.x = b
assert c.q.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: B = None
        self.x: B = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
m = C("m")
a = D("a")
i = A("i")

c.r = m
c.q = b
c.x = b
b.s = m
b.t = m
b.y = i
b.x = a
m.o = a
a.t = b
i.r = m
i.q = b
i.x = b
assert c.q.t.o.t.txt == "b"