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

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

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

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

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

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

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

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

m.r = f
m.p = f
f.w = m
f.t = m
a.q = c
a.r = m
a.t = f
c.q = j
c.r = m
c.t = f
j.q = c
j.r = m
j.t = f
assert a.t.t.p.t.r.txt == "f"