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

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

j = A("j")
f = B("f")
m = A("m")
h = A("h")
c = A("c")

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

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

j = A("j")
f = B("f")
m = A("m")
h = A("h")
c = A("c")

j.p = c
j.q = f
f.t = m
m.p = c
m.q = f
h.p = c
h.q = f
c.p = j
c.q = f
assert j.p.q.t.p.txt == "c"