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

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

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

g = A("g")
j = B("j")
h = C("h")
n = A("n")
d = B("d")
k = C("k")
f = C("f")
l = C("l")
m = A("m")
b = C("b")

g.r = m
g.t = j
j.x = g
j.q = d
j.t = f
h.s = j
h.t = j
n.r = m
n.t = j
d.x = n
d.q = j
d.t = h
k.s = d
k.t = j
f.s = d
f.t = d
l.s = j
l.t = d
m.r = n
m.t = j
b.s = j
b.t = d
assert g.t.x.t.q.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: B = None
        self.txt = txt

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

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

g = A("g")
j = B("j")
h = C("h")
n = A("n")
d = B("d")
k = C("k")
f = C("f")
l = C("l")
m = A("m")
b = C("b")

g.r = m
g.t = j
j.x = g
j.q = d
j.t = f
h.s = j
h.t = j
n.r = m
n.t = j
d.x = n
d.q = j
d.t = h
k.s = d
k.t = j
f.s = d
f.t = d
l.s = j
l.t = d
m.r = n
m.t = j
b.s = j
b.t = d
assert g.t.x.t.q.x.txt == "n"