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

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

d = A("d")
k = B("k")
e = A("e")
c = A("c")
f = B("f")
j = A("j")
g = B("g")

d.o = j
k.o = g
e.o = j
c.o = j
f.o = g
j.o = d
g.o = k
assert k.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

d = A("d")
k = B("k")
e = A("e")
c = A("c")
f = B("f")
j = A("j")
g = B("g")

d.o = j
k.o = g
e.o = j
c.o = j
f.o = g
j.o = d
g.o = k
assert k.o.o.o.o.txt == "k"