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

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

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

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

j = A("j")
a = B("a")
d = C("d")
m = D("m")
c = D("c")
k = D("k")
b = A("b")
l = D("l")
g = B("g")
i = C("i")

j.q = b
a.t = j
a.p = j
a.q = b
d.r = i
d.x = j
m.o = d
m.q = g
c.o = d
c.q = a
k.o = d
k.q = g
b.q = j
l.o = d
l.q = g
g.t = j
g.p = b
g.q = b
i.r = d
i.x = j
assert k.o.x.q.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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

j = A("j")
a = B("a")
d = C("d")
m = D("m")
c = D("c")
k = D("k")
b = A("b")
l = D("l")
g = B("g")
i = C("i")

j.q = b
a.t = j
a.p = j
a.q = b
d.r = i
d.x = j
m.o = d
m.q = g
c.o = d
c.q = a
k.o = d
k.q = g
b.q = j
l.o = d
l.q = g
g.t = j
g.p = b
g.q = b
i.r = d
i.x = j
assert k.o.x.q.q.q.q.q.q.txt == "j"