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

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

f = A("f")
a = B("a")
g = A("g")
k = B("k")
h = A("h")
l = B("l")

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

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

f = A("f")
a = B("a")
g = A("g")
k = B("k")
h = A("h")
l = B("l")

f.p = h
f.t = l
a.o = h
g.p = f
g.t = k
k.o = g
h.p = f
h.t = a
l.o = f
assert g.p.p.t.txt == "a"