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

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

e = A("e")
i = B("i")
h = B("h")
j = B("j")

e.p = i
e.v = h
i.p = e
i.q = e
h.p = e
h.q = e
j.p = e
j.q = e
assert h.p.v.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.v: B = None
        self.txt = txt

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

e = A("e")
i = B("i")
h = B("h")
j = B("j")

e.p = i
e.v = h
i.p = e
i.q = e
h.p = e
h.q = e
j.p = e
j.q = e
assert h.p.v.p.v.txt == "h"