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

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

c = A("c")
e = B("e")
m = A("m")
h = A("h")

c.q = e
c.p = m
e.y = m
m.q = e
m.p = h
h.q = e
h.p = m
assert e.y.q.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: A = None
        self.txt = txt

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

c = A("c")
e = B("e")
m = A("m")
h = A("h")

c.q = e
c.p = m
e.y = m
m.q = e
m.p = h
h.q = e
h.p = m
assert e.y.q.y.txt == "m"