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

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

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

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

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

i.u = l
g.p = l
g.x = l
g.t = i
g.q = b
l.w = a
l.z = i
l.t = b
l.s = b
b.r = g
b.y = l
a.u = l
m.u = l
assert b.r.q.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

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

i.u = l
g.p = l
g.x = l
g.t = i
g.q = b
l.w = a
l.z = i
l.t = b
l.s = b
b.r = g
b.y = l
a.u = l
m.u = l
assert b.r.q.r.t.txt == "i"