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

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

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

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

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

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

c.q = g
c.p = n
h.t = n
g.q = c
g.p = n
n.t = h
assert c.q.p.t.txt == "h"