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

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

d = A("d")
g = B("g")
b = B("b")
h = B("h")

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

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

d = A("d")
g = B("g")
b = B("b")
h = B("h")

d.q = b
g.t = h
g.p = d
b.t = h
b.p = d
h.t = g
h.p = d
assert h.p.q.t.txt == "h"