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

e = A("e")
f = B("f")
g = A("g")

e.o = f
e.p = f
f.t = g
f.y = e
g.o = f
g.p = f
assert f.y.p.t.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.y: A = None
        self.txt = txt

e = A("e")
f = B("f")
g = A("g")

e.o = f
e.p = f
f.t = g
f.y = e
g.o = f
g.p = f
assert f.y.p.t.txt == "g"