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

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

class C:
    def __init__(self, txt: str):
        self.v: C = None
        self.o: C = None
        self.r: C = None
        self.txt = txt

c = A("c")
h = B("h")
f = C("f")
k = B("k")
a = A("a")
m = C("m")

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

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

class C:
    def __init__(self, txt: str):
        self.v: C = None
        self.o: C = None
        self.r: C = None
        self.txt = txt

c = A("c")
h = B("h")
f = C("f")
k = B("k")
a = A("a")
m = C("m")

c.p = k
c.r = a
h.q = a
h.w = c
f.v = m
f.o = m
f.r = m
k.q = a
k.w = a
a.p = k
a.r = c
m.v = f
m.o = f
m.r = f
assert a.r.p.q.txt == "a"