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

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

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

m = A("m")
f = B("f")
a = C("a")
g = A("g")
h = B("h")

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

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

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

m = A("m")
f = B("f")
a = C("a")
g = A("g")
h = B("h")

m.t = g
m.w = a
f.r = m
f.q = a
a.p = m
g.t = m
g.w = a
h.r = g
h.q = a
assert a.p.w.p.w.txt == "a"