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

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

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

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

b = A("b")
m = B("m")
a = C("a")
d = D("d")
g = B("g")

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

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

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

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

b = A("b")
m = B("m")
a = C("a")
d = D("d")
g = B("g")

b.r = g
b.s = g
b.q = d
m.t = d
a.z = d
a.q = g
a.s = b
d.r = g
d.t = a
g.t = d
assert g.t.t.q.t.t.txt == "a"