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

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

f = A("f")
b = B("b")
n = A("n")
c = B("c")
g = A("g")
j = B("j")

f.o = g
f.t = n
b.s = g
n.o = g
n.t = f
c.s = n
g.o = f
g.t = n
j.s = g
assert n.t.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.t: A = None
        self.txt = txt

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

f = A("f")
b = B("b")
n = A("n")
c = B("c")
g = A("g")
j = B("j")

f.o = g
f.t = n
b.s = g
n.o = g
n.t = f
c.s = n
g.o = f
g.t = n
j.s = g
assert n.t.o.o.o.txt == "g"