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

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

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

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

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

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

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

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

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

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

d.q = c
d.x = m
b.s = m
b.p = m
b.u = m
b.q = l
f.t = l
m.o = l
m.r = l
m.x = l
m.v = f
g.s = m
g.p = m
g.u = m
g.q = f
c.q = d
c.x = m
l.t = f
assert g.q.t.t.t.t.t.t.txt == "f"