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

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

j = A("j")
m = B("m")
e = A("e")
g = B("g")

j.t = g
j.p = e
m.o = g
e.t = m
e.p = j
g.o = m
assert g.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.p: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
e = A("e")
g = B("g")

j.t = g
j.p = e
m.o = g
e.t = m
e.p = j
g.o = m
assert g.o.o.o.txt == "m"