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

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

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

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

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

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

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

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

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

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

a.o = d
a.r = b
a.w = b
a.x = c
b.t = a
b.q = c
b.w = l
l.r = g
l.z = a
g.q = b
g.s = b
c.q = b
c.s = b
d.o = a
d.r = b
d.w = b
d.x = c
assert g.q.t.w.txt == "b"