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

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

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

d = A("d")
h = B("h")
j = C("j")
c = C("c")
a = C("a")
g = A("g")
k = C("k")
l = B("l")
m = A("m")
n = B("n")

d.r = a
d.q = g
h.x = l
j.q = d
c.q = g
a.q = g
g.r = j
g.q = m
k.q = m
l.x = h
m.r = k
m.q = d
n.x = h
assert l.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.q: A = None
        self.txt = txt

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

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

d = A("d")
h = B("h")
j = C("j")
c = C("c")
a = C("a")
g = A("g")
k = C("k")
l = B("l")
m = A("m")
n = B("n")

d.r = a
d.q = g
h.x = l
j.q = d
c.q = g
a.q = g
g.r = j
g.q = m
k.q = m
l.x = h
m.r = k
m.q = d
n.x = h
assert l.x.x.x.x.x.x.x.txt == "h"