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

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

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

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

g = A("g")
i = B("i")
c = C("c")
d = D("d")
f = A("f")
l = C("l")
m = A("m")
j = D("j")

g.t = m
i.q = f
i.u = d
i.x = c
c.w = m
d.p = l
d.u = l
d.o = g
d.s = g
f.t = m
l.w = g
m.t = f
j.p = l
j.u = c
j.o = f
j.s = m
assert j.p.w.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

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

g = A("g")
i = B("i")
c = C("c")
d = D("d")
f = A("f")
l = C("l")
m = A("m")
j = D("j")

g.t = m
i.q = f
i.u = d
i.x = c
c.w = m
d.p = l
d.u = l
d.o = g
d.s = g
f.t = m
l.w = g
m.t = f
j.p = l
j.u = c
j.o = f
j.s = m
assert j.p.w.t.t.t.txt == "m"