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: B = None
        self.y: A = None
        self.txt = txt

d = A("d")
i = B("i")
h = A("h")
b = A("b")
e = A("e")
j = B("j")
n = B("n")

d.p = h
d.q = n
i.t = n
i.y = b
h.p = b
h.q = n
b.p = e
b.q = j
e.p = d
e.q = i
j.t = i
j.y = b
n.t = i
n.y = b
assert d.q.t.t.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: B = None
        self.y: A = None
        self.txt = txt

d = A("d")
i = B("i")
h = A("h")
b = A("b")
e = A("e")
j = B("j")
n = B("n")

d.p = h
d.q = n
i.t = n
i.y = b
h.p = b
h.q = n
b.p = e
b.q = j
e.p = d
e.q = i
j.t = i
j.y = b
n.t = i
n.y = b
assert d.q.t.t.txt == "n"