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

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

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

g = A("g")
n = B("n")
h = C("h")
e = B("e")
c = A("c")
b = B("b")
l = C("l")
a = B("a")
m = C("m")

g.q = a
g.p = c
n.x = a
n.p = m
h.w = e
h.r = a
h.t = b
e.x = n
e.p = h
c.q = b
c.p = g
b.x = n
b.p = l
l.w = n
l.t = n
l.r = e
a.x = e
a.p = l
m.w = b
m.r = a
m.t = n
assert h.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: A = None
        self.txt = txt

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

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

g = A("g")
n = B("n")
h = C("h")
e = B("e")
c = A("c")
b = B("b")
l = C("l")
a = B("a")
m = C("m")

g.q = a
g.p = c
n.x = a
n.p = m
h.w = e
h.r = a
h.t = b
e.x = n
e.p = h
c.q = b
c.p = g
b.x = n
b.p = l
l.w = n
l.t = n
l.r = e
a.x = e
a.p = l
m.w = b
m.r = a
m.t = n
assert h.r.p.r.txt == "e"