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

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

n = A("n")
c = B("c")
m = A("m")
g = B("g")

n.p = m
c.t = m
m.p = n
g.t = n
assert c.t.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

n = A("n")
c = B("c")
m = A("m")
g = B("g")

n.p = m
c.t = m
m.p = n
g.t = n
assert c.t.p.p.p.txt == "n"