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

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

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

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

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

l.q = g
l.x = c
k.o = l
k.q = d
h.p = b
h.r = g
f.o = i
f.r = l
f.z = j
f.w = h
g.o = l
g.q = d
i.p = d
i.r = d
j.o = c
j.q = b
c.q = k
c.x = l
d.o = l
d.q = j
b.o = c
b.q = d
assert h.r.o.q.o.x.q.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.x: A = None
        self.txt = txt

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

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

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

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

l.q = g
l.x = c
k.o = l
k.q = d
h.p = b
h.r = g
f.o = i
f.r = l
f.z = j
f.w = h
g.o = l
g.q = d
i.p = d
i.r = d
j.o = c
j.q = b
c.q = k
c.x = l
d.o = l
d.q = j
b.o = c
b.q = d
assert h.r.o.q.o.x.q.o.q.txt == "g"