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

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

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

b = A("b")
j = B("j")
m = C("m")
l = A("l")
c = C("c")
i = C("i")
f = B("f")

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

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

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

b = A("b")
j = B("j")
m = C("m")
l = A("l")
c = C("c")
i = C("i")
f = B("f")

b.q = f
j.u = f
j.r = b
m.q = j
m.u = l
m.p = f
l.q = f
c.q = j
c.p = j
c.u = l
i.q = f
i.p = f
i.u = l
f.u = j
f.r = l
assert b.q.u.u.u.r.txt == "b"