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

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

h = A("h")
a = B("a")
c = A("c")
f = A("f")

h.o = c
h.r = f
a.s = f
c.o = h
c.r = f
f.o = c
f.r = c
assert c.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: A = None
        self.txt = txt

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

h = A("h")
a = B("a")
c = A("c")
f = A("f")

h.o = c
h.r = f
a.s = f
c.o = h
c.r = f
f.o = c
f.r = c
assert c.o.o.o.txt == "h"