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

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

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

c.o = e
c.x = k
g.r = e
g.t = c
e.r = g
e.t = c
k.o = d
k.x = c
d.r = e
d.t = k
assert d.t.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.x: A = None
        self.txt = txt

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

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

c.o = e
c.x = k
g.r = e
g.t = c
e.r = g
e.t = c
k.o = d
k.x = c
d.r = e
d.t = k
assert d.t.o.t.txt == "k"