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

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

c = A("c")
b = B("b")
g = A("g")
k = A("k")
m = A("m")
j = B("j")
a = A("a")
n = B("n")

c.t = m
c.p = j
b.r = n
b.p = g
g.t = c
g.p = n
k.t = g
k.p = n
m.t = a
m.p = b
j.r = n
j.p = c
a.t = c
a.p = j
n.r = b
n.p = m
assert a.p.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: B = None
        self.txt = txt

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

c = A("c")
b = B("b")
g = A("g")
k = A("k")
m = A("m")
j = B("j")
a = A("a")
n = B("n")

c.t = m
c.p = j
b.r = n
b.p = g
g.t = c
g.p = n
k.t = g
k.p = n
m.t = a
m.p = b
j.r = n
j.p = c
a.t = c
a.p = j
n.r = b
n.p = m
assert a.p.p.t.txt == "m"