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

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

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

b.o = i
b.p = j
i.t = b
i.x = b
j.t = h
j.x = b
h.o = j
h.p = i
assert i.x.p.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: B = None
        self.txt = txt

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

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

b.o = i
b.p = j
i.t = b
i.x = b
j.t = h
j.x = b
h.o = j
h.p = i
assert i.x.p.x.o.txt == "i"