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

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

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

f = A("f")
l = B("l")
a = C("a")
d = A("d")
h = B("h")
m = B("m")
j = C("j")
c = A("c")

f.u = m
f.r = d
l.u = h
a.q = l
a.w = j
a.p = c
d.u = m
d.r = f
h.u = l
m.u = l
j.q = h
j.w = a
j.p = d
c.u = l
c.r = d
assert j.p.r.u.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.r: A = None
        self.txt = txt

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

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

f = A("f")
l = B("l")
a = C("a")
d = A("d")
h = B("h")
m = B("m")
j = C("j")
c = A("c")

f.u = m
f.r = d
l.u = h
a.q = l
a.w = j
a.p = c
d.u = m
d.r = f
h.u = l
m.u = l
j.q = h
j.w = a
j.p = d
c.u = l
c.r = d
assert j.p.r.u.u.u.u.u.txt == "h"