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

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

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

m = A("m")
f = B("f")
b = C("b")
g = C("g")
a = C("a")
k = C("k")
l = A("l")

m.r = l
m.q = b
f.p = a
b.t = f
b.r = l
g.t = f
g.r = l
a.t = f
a.r = m
k.t = f
k.r = l
l.r = m
l.q = g
assert g.r.r.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: C = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
b = C("b")
g = C("g")
a = C("a")
k = C("k")
l = A("l")

m.r = l
m.q = b
f.p = a
b.t = f
b.r = l
g.t = f
g.r = l
a.t = f
a.r = m
k.t = f
k.r = l
l.r = m
l.q = g
assert g.r.r.q.r.txt == "l"