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

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

h = A("h")
k = B("k")
l = B("l")

h.t = k
k.o = h
k.p = h
l.o = h
l.p = h
assert k.p.t.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
l = B("l")

h.t = k
k.o = h
k.p = h
l.o = h
l.p = h
assert k.p.t.o.txt == "h"